﻿using EasyERP_DAL;
using EasyERP_DAL.Wares;
using EasyERP_Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyERP_BLL.Wares
{
    /// <summary>
    /// 往来单价业务逻辑类
    /// </summary>
    public class B_Item_Price_BLL
    {
        /// <summary>
        /// 往来单价数据访问对象
        /// </summary>
        private readonly B_Item_Price_DAL Item_Price_DAL = new B_Item_Price_DAL();

        #region 查询商品往来单价信息
        /// <summary>
        /// 查询商品往来单价信息
        /// </summary>
        /// <param name="item_Price">往来单价实体类</param>
        /// <param name="item">商品信息实体类</param>
        /// <returns>返回商品往来单价信息</returns>
        public DataTable Get_B_Item_Price(B_Item_Price item_Price, B_Item item)
        {
            try
            {
                return Item_Price_DAL.Get_B_Item_Price(item_Price, item);
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);
                return null;
            }
        }
        #endregion

        #region 添加商品单价信息
        /// <summary>
        /// 添加商品单价信息
        /// </summary>
        /// <param name="model">商品单价实体类</param>
        /// <returns>返回True：成功；False：失败；</returns>
        public bool Insert_B_Item_Price(B_Item_Price model)
        {
            if (string.IsNullOrWhiteSpace(model.bp_cd))                     //单位码编为空
            {
                B_Message_BLL.MessageCaveat("2020");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.item_cd))                   //商品码编为空
            {
                B_Message_BLL.MessageCaveat("2015");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.item_price.ToString()))     //商品单价为空
            {
                B_Message_BLL.MessageCaveat("2017");                        //弹出提示框
                return false;
            }

            //保存前验证数据是否存在
            if (Item_Price_DAL.Exists(model))      //存在
            {
                B_Message_BLL.MessageCaveat("1001");        //弹出提示框
                return false;
            }

            try
            {
                return Item_Price_DAL.Insert_B_Item_Price(model);
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);
                return false;
            }
        }
        #endregion

        #region 删除商品单价信息
        /// <summary>
        /// 删除商品单价信息
        /// </summary>
        /// <param name="model">商品单价实体类</param>
        /// <returns>返回True：成功；False：失败；</returns>
        public bool Delete_B_Item_Price(B_Item_Price model)
        {
            if (string.IsNullOrWhiteSpace(model.bp_cd))                     //单位码编为空
            {
                B_Message_BLL.MessageCaveat("2020");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.item_cd))                   //商品码编为空
            {
                B_Message_BLL.MessageCaveat("2015");                        //弹出提示框
                return false;
            }

            if (Item_Price_DAL.Exists(model))                               //判断要删除的数据存在
            {
                try
                {
                    return Item_Price_DAL.Delete_B_Item_Price(model);       //删除数据
                }
                catch (Exception ex)
                {
                    B_Message_BLL.MessageCaveat(ex);
                    return false;
                }
            }
            B_Message_BLL.MessageCaveat("1002");                            //弹出提示框
            return false;
        }
        #endregion

        #region 修改商品单价信息
        /// <summary>
        /// 修改商品单价信息
        /// </summary>
        /// <param name="model">商品单价实体类</param>
        /// <returns>返回True：成功；False：失败；</returns>
        public bool Update_B_Item_Price(B_Item_Price model)
        {
            if (string.IsNullOrWhiteSpace(model.bp_cd))                     //单位码编为空
            {
                B_Message_BLL.MessageCaveat("2020");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.item_cd))                   //商品码编为空
            {
                B_Message_BLL.MessageCaveat("2015");                        //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.item_price.ToString()))     //商品单价为空
            {
                B_Message_BLL.MessageCaveat("2017");                        //弹出提示框
                return false;
            }

            if (Item_Price_DAL.Exists(model))                               //判断要修改的数据存在
            {
                try
                {
                    return Item_Price_DAL.Update_B_Item_Price(model);       //修改数据
                }
                catch (Exception ex)
                {
                    B_Message_BLL.MessageCaveat(ex);
                    return false;
                }
            }
            B_Message_BLL.MessageCaveat("1003");                            //弹出提示框
            return false;
        }
        #endregion
    }
}
